package com.xjust.service.impl;


import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.xjust.Mapper.InspectionRequestMapper;
import com.xjust.Mapper.RegisterMapper;
import com.xjust.pojo.ResultBean;
import com.xjust.service.InspectionRequestService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Service
public class InspectionRequestSreviceImpl implements InspectionRequestService {
    @Autowired
   private InspectionRequestMapper inspectionRequestMapper;
    @Autowired
    private RegisterMapper registerMapper;
    //保存检验申请表
    @Override
    public void saveInspectionRequest(Map<String, Object> inspectionRequest) {
        LocalDateTime creationTime = LocalDateTime.now();
        inspectionRequest.put("creationTime",creationTime);
        inspectionRequestMapper.insertInspectionRequest(inspectionRequest);
    }
    //检验申请
    @Override
    public ResultBean getInspectionRequests(Integer page, Integer pageSize, String caseNumber, String realName) {
        List<Map<String, Object>> list = inspectionRequestMapper.getInspectionRequests();
        List<Integer> idList = new ArrayList<>();
        if (list.size() != 0) {
            for (Map<String, Object> regist : list) {
                if (regist.get("register_id") != null) {
                    idList.add((Integer) regist.get("register_id"));
                }
            }
            Integer[] registIdList = idList.toArray(new Integer[idList.size()]);
            PageHelper.startPage(page, pageSize);
            Page<Map<String, Object>> pageInfo = registerMapper.selectRegisterById(registIdList, realName, caseNumber);
            ResultBean pageBean = new ResultBean();
            pageBean.setRows(pageInfo.getResult());
            pageBean.setCount(pageInfo.getTotal());
            return pageBean;
        } else {
            return null;
        }

    }
    //提交患者检验信息
    @Override
    public void submitInspectionRequest(Integer employeeId, Integer registId, Integer medicalTechnology) {
            String inspectionState = "执行完成";
            inspectionRequestMapper.updataInspection(employeeId,registId,medicalTechnology,inspectionState);
    }
    //获取已完成患者数量
    @Override
    public Integer getFinishInspectionList() {
        return inspectionRequestMapper.getFinishInspectionList();
    }
    //获取等待患者数量
    @Override
    public Integer getWaitInspectionList() {
        return inspectionRequestMapper.getWaitInspectionList();
    }

}
